/**
 * Copyright (C), 2019-2020, 宇信融汇
 * FileName: GenericTest
 * Author:   xbliu
 * Date:     2020/7/24 14:41
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * xbliu           修改时间           版本号              描述
 */
package c_010.generic;

import org.junit.Test;

import java.util.*;

/**
 * @Classname GenericTest
 * @Description TODO
 * @Date 2020/7/24 14:41
 * @Created by xbliu
 */
public class GenericTest {
    //在list中使用泛型，添加的元素要为同一类型
    @Test
    public void test1() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(111);
        list.add(222);
        list.add(333);
        list.add(444);
        for (Integer i : list) {
            System.out.println(i);
        }
        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

    @Test
    public void test2() {
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        map.put("tom", 11);
        map.put("jack", 22);
        map.put("meray", 33);
        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        Iterator<Map.Entry<String, Integer>> iterator = entrySet.iterator();
        while(iterator.hasNext()){
            Map.Entry<String, Integer> e = iterator.next();
            String key =e.getKey();
            Integer value = e.getValue();
            System.out.println(key+"----"+value);
        }

    }
}
